package com.zsc.boot.config;

import io.lettuce.core.RedisClient;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class RedisConfig {

    //注意这个变量名要与yml一致
    private String host;
    private String port;

    @Bean
    public RedissonClient redissonClient() {
        //1、创建配置
        Config config = new Config();
        String address = String.format("redis://%s:%s", host, port);
        config.useSingleServer().setAddress(address).setDatabase(3);
        //2、创建实例
        RedissonClient redissonClient = Redisson.create(config);

        return redissonClient;
    }
}
